package com.itheima.youdianda.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.youdianda.common.R;
import com.itheima.youdianda.domain.YddCate;
import com.itheima.youdianda.dto.PageDto;
import com.itheima.youdianda.service.YddCateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * @ClassName YddCatecontroller
 * @Description 分类管理
 * @Author dcq
 * @Date 2023/2/12 13:38
 * @Version 1.0
 */
@RestController
@RequestMapping("/ydd_cate")
public class YddCateController {
    @Autowired
    private YddCateService yddCateServie;

    /**
     * 分类详情
     * @param id
     * @return
     */
    @GetMapping("/rowInfo")
    public R<YddCate> rowinfo(String id){
        YddCate byId = yddCateServie.getById(id);
        return  R.success(byId);
    }

    /**
     *  分类列表分页
     * @param page
     * @param limit
     * @param catename
     * @return
     */
    @GetMapping("/list")
    public R<PageDto>list(String page, String limit, String catename){
        PageDto mypage = yddCateServie.mypage(page, limit, catename);
        return R.success(mypage);

    }

    /**
     * 分页删除
     * @param id
     * @return
     */
    @GetMapping("/del")
    public  R<String> del( Integer id){
        yddCateServie.removeById(id);
         return R.success("删除成功");
    }

    /**
     * 修改
     * @param yddCate
     * @return
     */
    @PostMapping("/update")
    public R<String>update(@RequestBody  YddCate yddCate){
        LambdaQueryWrapper<YddCate>queryWrapper=new LambdaQueryWrapper<>();
        queryWrapper.eq(YddCate::getId,yddCate.getId());
        yddCateServie.update(yddCate,queryWrapper);
        return R.success("修改成功");
    }

    /**
     * 添加
     * @param yddCate
     * @return
     */
    @PostMapping("/add")
    public R<String> add(@RequestBody YddCate yddCate){
        yddCateServie.save(yddCate);
        return  R.success("添加成功");
    }

    /**
     * 展现全部
     * @return
     */
    @GetMapping("/all")
    public R<List<YddCate>> all(){
        List<YddCate> list = yddCateServie.list();
        return R.success(list);
    }
    @GetMapping("")// TODO: 2023/2/12   不知道传回方法
    public R<YddCate> getby(String id){
        YddCate byId = yddCateServie.getById(id);
        return  R.success(byId
        );
    }

}